﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.Text;
using System.IO;
using WCFServiceWebRole1.Services;
using System.Diagnostics;
using System.ServiceModel.Web;
using System.ServiceModel.Description;
using System.ServiceModel;

namespace WCFServiceWebRole1_Tests
{
    [TestClass]
    public class UnitTest1
    {
        public static User_Rest_Host UserRestHost { get; set; }
        public static Iusers UserRest { get; set; }

        [ClassInitialize()]
        public static void classInitialization(TestContext testcontext)
        {
            Debug.Print("Starting Host");
            UserRestHost = new User_Rest_Host().StartHost();
            UserRest = UserRestHost.GetProxy();
        }

        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            
        }
        [TestMethod]
        public void TestMethod1()
        {
            var factory = new WebChannelFactory<Iusers>(new WebHttpBinding(), new Uri("http://localhost:8181/Services/users.svc"));
            factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
            Iusers client = factory.CreateChannel();

            using (new OperationContextScope((IContextChannel)client))
            {
                if (WebOperationContext.Current != null)
                    WebOperationContext.Current.OutgoingRequest.ContentType = "application/json";
                Console.WriteLine(client.getUserByUserId("1092"));
            }

          
            //var devices = UserRest.getUserByUserId("1092");
            //Debug.Print("User Name" + devices.response.FirstName);
            ////foreach (var dev in devices.Public)
            ////{

            ////    Debug.Print(dev.Name);
            ////}
            //Assert.Equals(devices.response.FirstName, "ayyappan");




            //WebRequest request = WebRequest.Create("http://localhost:20000/Services/users.svc/user/69");
            //WebResponse ws = request.GetResponse();
            //Encoding enc = System.Text.Encoding.GetEncoding(1252);
            //StreamReader responseStream = new StreamReader(ws.GetResponseStream());
            //string response = responseStream.ReadToEnd();
            //responseStream.Close();
            //Debug.Print(response);
            ////MessageBox.Show(response);
        }
    }
}
